function payment(data) {
    switch (data.code) {
        case 1://系统内账户支付
            layer.msg(data.msg, {time: 1500}, function () {
                if (data.url) {
                    location.href = data.url;
                } else {
                    window.location.reload();
                }
            });
            break;
        case 3://支付宝H5支付
            layer.msg('正在拉取支付...', {time: 1000}, function () {
                $('body').append(data.data);
                document.forms['alipaysubmit'].submit();
            });
            break;
        case 4://微信H5支付
            layer.msg('正在拉取支付...', {time: 1000}, function () {
                window.location.href = data.data;
            });
            break;
        case 5://微信JSAPI支付
            layer.msg('正在拉取支付...', {time: 1000}, function () {
                callpay(data.data);
            });
            break;
        default:
            if (data.url) {
                layer.msg(data.msg, {time: 1000}, function () {
                    location.href = data.url;
                });
            } else {
                layer.msg(data.msg);
            }

    }
}

function jsApiCall(data) {
    WeixinJSBridge.invoke(
        'getBrandWCPayRequest', {
            "appId": data.appId,
            "nonceStr": data.nonceStr,
            "package": data.package,
            "paySign": data.paySign,
            "signType": data.signType,
            "timeStamp": data.timeStamp,
        },
        function (res) {
            console.log(res);
            if (res.err_msg == "get_brand_wcpay_request:ok") {
                location.href = '/index/order/my_order.html';
            } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
                location.reload();
            }
        }
    );
}

function callpay(data) {

    if (typeof WeixinJSBridge == "undefined") {
        if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', jsApiCall(data), false);
        } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', jsApiCall(data));
            document.attachEvent('onWeixinJSBridgeReady', jsApiCall(data));
        }
    } else {
        jsApiCall(data);
    }
}